import config from '@/common/config.js'

const $request = (url, data, method = 'GET', headers = {}) => {
	return new Promise((resolve, reject) => {
		// uni.showLoading({
		// 	title: '加载中',
		// 	icon: 'loading',
		// 	mask: true
		// });
		console.log(1111,config.baseURL + url)
		if(uni.getStorageSync('token')){
			headers = {
				Authorization: uni.getStorageSync('token')
			}
		}
		uni.request({
			url: config.baseURL + url,
			method: method,
			data: data,
			header: {
				'Content-Type': "application/json",
				...headers
			},
			success(res) {
				console.log(res,11111)
				resolve(res.data)
				// uni.hideLoading(); //关闭loading
			},
			fail(error) {
				reject(error);
				// uni.hideLoading(); //关闭loading
			},
			complete() {
				// uni.hideLoading(); //关闭loading
			}
		})
	})
}
//给uniapp原生的requset赋值
//记得要在mian.js中引用
uni.$request = $request